import { cloudService } from './index'
import { IPlanInfo, IPlanQuery } from '@/types/plan.ts'

export const addPlanApi = (plan: IPlanInfo): Promise<any> =>
  cloudService({
    url: '/home-api/plan',
    method: 'post',
    data: plan
  })

export const updatePlanApi = (id: number, plan: IPlanInfo): Promise<any> =>
  cloudService({
    url: `/home-api/plan/${id}`,
    method: 'put',
    data: plan
  })

export const setPlanStatusApi = (id: number, status: boolean): Promise<any> =>
  cloudService({
    url: `/home-api/plan/${id}/status`,
    method: 'put',
    params: { status }
  })

export const deletePlanApi = (id: number): Promise<any> =>
  cloudService({
    url: `/home-api/plan/${id}`,
    method: 'delete'
  })

export const queryPlanApi = (query: IPlanQuery): Promise<any> =>
  cloudService({
    url: '/home-api/plan',
    method: 'get',
    params: query
  })

export const queryPlanStatsApi = (): Promise<any> =>
  cloudService({
    url: '/home-api/plan/stats',
    method: 'get'
  })
